home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: wgk@zurich.ibm.com (Keith Whittingham)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this a memory leak?
- Date: 5 Apr 1996 14:07:33 GMT
- Organization: IBM Research, ZRH
- Message-ID: <4k39f5$lhn@grimsel.zurich.ibm.com>
- References: <4jv214$gv7@insosf1.netins.net> <4k02v5$tu7@grimsel.zurich.ibm.com> <4k2vku$s82@werple.net.au>
- Reply-To: wgk@zurich.ibm.com
- NNTP-Posting-Host: pine.zurich.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.00
-
- In <4k2vku$s82@werple.net.au>, davidw@werple.net.au (David White) writes:
- >wgk@zurich.ibm.com (Keith Whittingham) writes:
- >
- >
- ME>>The dto, ~TopClass, is a going to try and free some memory at the address
- ME>>0x000 but, by a quirk of implmentation, will probably not blow up (as a
- ME>>simple call to free(0) would). Instead the compiler probably generates
- ME>>code to check that the object address is 0, it so there is no deallocation
- ME>>of the memory.
- >
- >The use of 0 as a pointer is not the address 0x000. It is a null pointer
- >as defined by the language. Implementations are not even required to use a
- >bit pattern of all zeroes as a null pointer. They can use any value they
- >like, as long as it will not also be used as a real address. Furthermore,
- >rather than being a quirk of implementation, the language guarantees that
- >deleting a null pointer will do nothing.
- >
-
- Er, I don't think I agree.
-
- The line of code (if I remember correctly) was:
-
- bury = 0;
-
- 'bury' being a pointer to some element. bury *is* a pointer and it is
- assigned the value 0. 0 is the same as 0x0000. The line of code:
-
- bury = NULL;
-
- may of course set bury to some other value.
-
- If, for some compiler, a NULL pointer was implemented as a bit pattern
- of all ones then we could expect the code:
-
- bury = 0;
- delete bury;
-
- to have some very strange behaviour. Whereas
-
- bury = NULL;
- delete bury;
-
- would be 'safe' although undesireable.
-
- In the real world most, if not all, compilers (I know of no exceptions)
- use the value 0 for a NULL pointer. As the original poster is trying
- to understand why his compiler is behaving the way it is I don't think
- that things need to be complicated with pathological cases.
-
- "Quirk of implementation" should have read, as you point out,
- "quirk of the language". I believe it is a 'quirk' as it is simply there
- to stop automatic deletion of objects for which construction failed
- due to lack of memory. I would consider explicit use of this 'feature'
- shoddy programming but then I'm an awkward sod...
-
- Keith
-
-
-
-